#import "UserInfoLogic.h"
@implementation UserInfoLogic
typedef void (^userinfo)(NSDictionary *info);
-(void)getUserInfoWithUID:(NSString *)uid
{
    NSMutableDictionary *modificationUser = [NSMutableDictionary dictionary];
    YYCache *yyCache = [[YYCache alloc] initWithName:KUserInfoCacheName];
    modificationUser = (NSMutableDictionary *)[yyCache objectForKey:KUserNickNameAndHeaderImage];
    if(modificationUser == nil)
    {
        modificationUser = [NSMutableDictionary dictionary];
    }
    NSString *ids = uid;
    NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"user_api" A:@"get_conversation_user_info"];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setObject:ids forKey:@"ids"];
    [CYNET POSTv2:url parameters:param responseCache:^(id responseObject) {
    } success:^(id responseObject) {
        YYCache *yyCache=[[YYCache alloc] initWithName:KUserInfoCacheName];
        NSArray *userList =  [responseObject valueForKey:@"list"];
        for (int i=0; i<userList.count; i++) {
            NSDictionary *model = userList[i];
            [modificationUser setObject:model forKey:[NSString stringWithFormat:@"%@",[model valueForKey:@"id"]]];
        }
        [yyCache setObject:modificationUser forKey:KUserNickNameAndHeaderImage];
        NSLog(ASLocalizedString(@"缓存存入%@"),[yyCache objectForKey:KUserNickNameAndHeaderImage]
              );
    } failure:^(NSString *error) {
    } hasCache:NO];
    NSLog(ASLocalizedString(@"222会话列表的用户列表%@"),ids);
}
-(void)getAllUserDataWithIds:(NSString *)ids
{
    NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"user_api" A:@"get_conversation_user_info"];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setObject:ids forKey:@"ids"];
    [CYNET POSTv2:url parameters:param responseCache:^(id responseObject) {
    } success:^(id responseObject) {
        YYCache *yyCache=[[YYCache alloc] initWithName:KUserInfoCacheName];
        NSArray *userList =  [responseObject valueForKey:@"list"];
        NSMutableDictionary *modificationUser = [NSMutableDictionary dictionary];
        for (int i=0; i<userList.count; i++) {
            NSDictionary *model = userList[i];
            [modificationUser setObject:model forKey:[NSString stringWithFormat:@"%@",[model valueForKey:@"id"]]];
        }
        [yyCache setObject:modificationUser forKey:KUserNickNameAndHeaderImage];
        NSLog(ASLocalizedString(@"缓存存入%@"),[yyCache objectForKey:KUserNickNameAndHeaderImage]
              );
    } failure:^(NSString *error) {
    } hasCache:NO];
    NSLog(ASLocalizedString(@"222会话列表的用户列表%@"),ids);
}
-(void)loadData
{
    NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"personal_api" A:@"get_user_page_info"];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setObject:SafeStr(self.uid) forKey:@"id"];
    [CYNET POST:url parameters:param responseCache:^(id responseObject) {
        self.model = [UserPageInfoModel modelWithDictionary:responseObject];
        if(self.model != nil)
        {
            if([self.delegagte respondsToSelector:@selector(requestDataCompleted)])
            {
                [self.delegagte requestDataCompleted];
            }
        }
    } success:^(id responseObject) {
        self.model = [UserPageInfoModel modelWithDictionary:responseObject];
        if(self.model != nil)
        {
            if([self.delegagte respondsToSelector:@selector(requestDataCompleted)])
            {
                [self.delegagte requestDataCompleted];
            }
        }
    } failure:^(NSString *error) {
    } hasCache:YES];
}
-(void)loadDataNoCache
{
    NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"personal_api" A:@"get_user_page_info"];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setObject:SafeStr(self.uid) forKey:@"id"];
    [CYNET POST:url parameters:param responseCache:^(id responseObject) {
    } success:^(id responseObject) {
        self.model = [UserPageInfoModel modelWithDictionary:responseObject];
        if(self.model != nil)
        {
            if([self.delegagte respondsToSelector:@selector(requestDataCompleted)])
            {
                [self.delegagte requestDataCompleted];
            }
        }
    } failure:^(NSString *error) {
    } hasCache:YES];
}
@end
